# = test.admin.11.rb - Admin, Mass Email Test
# 
# See LICENSE.txt for licensing details.
#
# == Description
# This will test the functionality to send mass email  .
#
require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'

    
	class TC_MassEmailTest_test < Test::Unit::TestCase
    
    def startup
      $Subject = randomChar(7)
      $Content = randomChar(10)
      
      @@ie = Watir::IE.start($SITE_URL)
	  end
	
	  def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
	  end
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      assert(ie.contains_text(/Community Server Announcements/))
      assert(ie.link(:text, /Administration/).exists?)
      ie.link(:text, /Administration/).click
      assert(ie.contains_text(/Community Server Announcements/))
    end
    
    def test_07_navigateToMassEmail
      ie.goto($SITE_URL + 'ControlPanel/Tools/MassEmailingAdmin.aspx')
    end

    def test_08_verifyLinksOnMassEmailPage
      assert(ie.link(:text, 'admin').exists?)
      assert(ie.link(:id, /logout$/).exists?)
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
      assert(ie.link(:text, 'Telligent').exists?)
      assert(ie.link(:id, /TaskRegion_SendButton$/).exists?)
    end
    
    def test_09_verifyFieldsOnMassEmailPage
      assert(ie.select_list(:id, /TaskRegion_RoleList$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_Subject$/).exists?)
    end
    
    def test_10_populateFieldsOnMassEmailPage
      ie.text_field(:id, /TaskRegion_Subject$/).set($Subject)
      ie.ie.Document.parentWindow.execScript("tinyMCE.getInstanceById(tinyMCE.getEditorId('mce_editor_0')).execCommand('mceSetContent', false, '" + $Content + "')")
    end
  
    def test_11_sendMassEmail
      ie.link(:id, /TaskRegion_SendButton$/).click
      assert(ie.contains_text('Message successfully sent'))
    end
    
    def test_99_closeIE
      ie.close
    end
    
  end